<?php

class Admin_content extends Admin_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('Admin_m');
    }

    function index() {
        is_admin();
        $this->list_page('accueil');
    }

    function list_page($page) {
        is_admin();
        $data = $this->Admin_m->list_content($page);
        $this->_data['accueil_data'] = $data;
        $this->_data['page'] = $page;
        $this->display_admin('admin/content/list_page_form');
    }

    function update_page($page, $id) {
        is_admin();
        $id = $this->uri->segment(4);
        $data = $this->Admin_m->get_content_details($page, $id);
        $this->_data['query'] = $data;

        $config = array(
            array(
                'field' => 'title',
                'label' => 'Titre',
                'rules' => 'required|xss_clean'
            ),
            array(
                'field' => 'content',
                'label' => 'Contenu',
                'rules' => 'required|xss_clean'
            )
        );
        $this->form_validation->set_rules($config);

        if ($this->input->post('submit')) {
            if ($this->form_validation->run()) {
                $title = $this->input->post('title');
                $content = $this->input->post('content');
                $update_query = $this->Admin_m->update_page($page, array('title' => $title, 'content' => $content), $id);
                if ($update_query == 1) {
                    $this->session->set_flashdata('alert', 'L\'article a été modifié !');
                } else {
                    $this->session->set_flashdata('alert', 'L\'article n\'est pas modifié, veuillez reessayer !');
                }
                redirect(base_url() . 'admin_content/list_page/' . $page);
            } else {
                $this->display_admin('admin/content/edit_page_form');
            }
        } else {
            $this->display_admin('admin/content/edit_page_form');
        }
    }

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
